package com.soft.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.soft.dao.CarInfoDao;
import com.soft.entity.*;
import com.soft.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.soft.service.CarInfoService;

import java.util.List;

@Service
@Transactional
public class CarInfoServiceImpl implements CarInfoService {

    @Autowired
    private CarInfoDao carInfoDao;

    @Override
    public ResultUtil getAllCarInfoList(Integer page, Integer limit,CarInfoSearch carInfoSearch) {
        PageHelper.startPage(page,limit);
        List<CarInfo> carInfos = carInfoDao.getAllCarInfoList(carInfoSearch);
        PageInfo<CarInfo> pageInfo = new PageInfo<CarInfo>(carInfos);
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setCode(0);
        resultUtil.setCount(pageInfo.getTotal());
        resultUtil.setData(pageInfo.getList());
        return resultUtil;
    }

    @Override
    public ResultUtil updateCarInfo(CarInfo carInfo) {
        carInfoDao.updateCarInfo(carInfo);
        return ResultUtil.ok();
    }

    @Override
    public CarInfo getCarInfoById(Integer carId) {
        return carInfoDao.getCarInfoById(carId);
    }

    @Override
    public CarInfo selCarInfoBynumber(String number) {
        return carInfoDao.selCarInfoBynumber(number);
    }

    @Override
    public void insertCarInfo(CarInfo carInfo) {
        carInfo.setCarId(carInfo.getCarId());
        carInfo.setNumber(carInfo.getNumber());
        carInfo.setTeamId(carInfo.getTeamId());
        carInfo.setType(carInfo.getType());
        carInfo.setSeatnum(carInfo.getSeatnum());
        carInfo.setBusMasterId(carInfo.getBusMasterId());
        carInfo.setStatus(carInfo.getStatus());
        carInfoDao.insertCarInfo(carInfo);
    }

    @Override
    public ResultUtil deleteCarInfoById(Integer carId) {
        carInfoDao.deleteCarInfoById(carId);
        return ResultUtil.ok();
    }
}
